<template>
  <el-dialog
    v-if="show"
    v-model="dialog"
    title="新增设备"
    class="AddEquipment"
    width="30%"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form :model="form" label-width="210px" ref="ruleFormRef" :rules="rules">
      <el-form-item label="设备编号：" prop="no">
        <el-input v-model="form.no" style="width: 170px" placeholder="请输入设备编号" />
      </el-form-item>
      <el-form-item label="关联司机：" prop="driver">
        <el-select v-model="form.driver" clearable style="width: 170px">
          <!-- <el-option
                      v-for="item in RUNTYPE_SELECT"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                  /> -->
        </el-select>
      </el-form-item>
    </el-form>
    <footer>
      <el-button type="primary" @click="onSubmit(ruleFormRef)">录 入</el-button>
    </footer>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref, withDefaults } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

const form = reactive({
  no: '',
  driver: '',
})
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules>({
  no: [{ required: true, message: '请输入设备编号', trigger: 'blur' }],
  driver: [{ required: true, message: '请选择司机', trigger: 'change' }],
})
interface Props {
  show: boolean
}
const dialog = ref(true)
withDefaults(defineProps<Props>(), {
  show: false,
})
const emit = defineEmits<{
  (event: 'update:show', val: boolean): void
}>()
//弹框关闭
const handleClose = () => {
  emit('update:show', false)
}
// 详情数据
const detailData = reactive({
  name: '',
})
//录入设备
const onSubmit = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}
</script>

<style lang="scss">
.AddEquipment {
  .el-dialog__body {
    padding: 0px 20px 10px;
  }
  footer {
    margin: 20px 0 10px;
    text-align: center;
  }
  .title {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #409eff;
  }
}
</style>
